<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
      label-width="68px">
      <el-form-item label="支付方式" prop="paymentMethod">
        <el-select v-model="queryParams.paymentMethod" placeholder="支付方式" clearable multiple
          style="width: 240px">
          <el-option v-for="dict in dict.type.pay_way" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="记账时间">
        <el-date-picker v-model="datetimeRange" style="width: 340px" value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange" range-separator="~" start-placeholder="开始时间" end-placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
          @click="handleExport" v-hasPermi="['statistics:finance:export']">导出
        </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="financeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" width="170" />
      <el-table-column label="发生时间" align="center" prop="occurrenceTime" :show-overflow-tooltip="true"
        width="160" />
      <el-table-column label="账单类型" align="center" prop="billingType" :show-overflow-tooltip="true"
        width="80" />
      <el-table-column label="付款流水号" align="center" prop="receivableNo" width="260" />
      <el-table-column label="订单ID" align="center" prop="orderId" width="160"
        :show-overflow-tooltip="true" />
      <el-table-column label="订单编号" prop="orderSn" :show-overflow-tooltip="true" width="200"
        align="center" />
      <el-table-column label="采购商编号" align="center" prop="purchaserBusinessCode" width="100"
        :show-overflow-tooltip="true" />
      <el-table-column label="采购商名称" align="center" prop="purchaserName" width="150"
        :show-overflow-tooltip="true" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="100"
        :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_order_status" :value="scope.row.orderStatus" />
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="flowPrice" width="80"
        :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:notice:edit']">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />-->
  </div>
</template>

<script>
import {
  listFinance
} from "@/api/financeAdmin/finance";
import axios from "axios";
import { getToken } from "@/utils/auth";
export default {
  name: "finance",
  dicts: ["order_order_status", "pay_way"],
  data () {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      //   total: 0,
      //账单表格数据
      financeList: [],
      // 日期范围
      datetimeRange: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        createBy: undefined,
        classify: undefined
      },
      // 表单参数
      form: {},
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      headers: {
        Authorization: "Bearer " + getToken(),
        "Content-Type": "multipart/form-data"
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "支付名称不能为空", trigger: "blur" }
        ],
        icon: [{ required: true, message: "图片不能为空", trigger: "change" }],
        account: [{ required: true, message: "账户不能为空", trigger: "blur" }],
        accountName: [
          { required: true, message: "开户名称不能为空", trigger: "blur" }
        ],
        bankName: [
          { required: true, message: "银行名称不能为空", trigger: "blur" }
        ],
        subbranch: [
          { required: true, message: "支行名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created () {
  },
  methods: {
    /** 查询支付方式列表 */
    getList () {
      this.loading = true;
      const that = this;
      listFinance(this.addDateRangeWithMap(this.queryParams, this.datetimeRange, "Time")).then(response => {
        that.financeList = response.data;
        that.total = response.total;
        that.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.datetimeRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.noticeId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 导出订单汇总按钮操作 */
    handleExport () {
      // ...this.queryParams
      this.download('statistics/finance/export', {
        ...this.addDateRangeWithMap(this.queryParams, this.datetimeRange, "Time")
      }, `对账单_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}:{i}:{s}")}.xlsx`)
    },
  }
};
</script>
